package com.example.mes.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
//
@Configuration
@EnableWebSecurity//启动spring security

public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        http.headers()//页面使用ifranme时使用配置

                .frameOptions().sameOrigin()
                .httpStrictTransportSecurity().disable();
//                    .csrf().disable();
        http.authorizeRequests()
               .antMatchers("/respository/**").permitAll()
                .antMatchers("/login").permitAll()//代表login不需要拦截
                .antMatchers("/**").fullyAuthenticated()
                .and()
                .formLogin()
                .loginPage("/login");
//                .failureUrl("login-error");
    }
    @Bean//注入PasswordEncoder
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();//进行密码多次的MD5加盐
    }

}
